<template>
    <div class="top">
        <div class="top-content">
            <!-- 左边 -->
            <div class="top-content-left">
                <img src="../../assets/images/logo.png">
                <router-link class="router-link-active" :to="{
                    path: '/home',
                }">
                    <p>挂号网 挂号统一平台</p>
                </router-link>
            </div>
            <!-- 右边 -->
            <div class="top-content-right">
                <p class="top-content-right-help">帮助中心</p>
                <!-- 未登录展示登录/注册 -->
                <p class="top-content-right-login" @click="login" v-if="!useStore.userInfo.name">登录/注册</p>
                <!-- 登录展示用户信息 -->
                <el-dropdown v-else :hide-on-click="false">
                    <span class="el-dropdown-link">
                    {{ useStore.userInfo.name }}    
                    <el-icon class="el-icon--right"><arrow-down /></el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item @click="goUser('/user/certification')">实名认证</el-dropdown-item>
                            <el-dropdown-item @click="goUser('/user/order')">挂号订单</el-dropdown-item>
                            <el-dropdown-item @click="goUser('/user/patient')">就诊人管理</el-dropdown-item>
                            <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>

            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
// 引入路由
import { useRouter } from 'vue-router';
import { ArrowDown } from '@element-plus/icons-vue'
// 获取user仓库的数据(visiable)可以控制login组件的对话框的显示与隐藏
import useUserStore from "../../store/modules/user";
let useStore = useUserStore();

let $router = useRouter();
// 点击登录与注册按钮的时候弹出对话框
const login = () => {
    useStore.visiable = true;
}
// 退出登录按钮的回调
const logout = () =>{
    // 通知pinia仓库清除用户相关的信息
    useStore.logout();
    // 编程式导航路由跳转到首页
    $router.push({path:'/home'})
}
// 点击顶部下拉菜单进行路由跳转
const goUser = (path:string)=>{
    $router.push({path:path})
}
</script>


<style scoped lang="scss">
.top {
    // 固定定位
    position: fixed;
    // 层级
    z-index: 999;
    width: 100%;
    height: 70px;
    background: white;
    display: flex;
    justify-content: center;

    .top-content {
        width: 86%;
        height: 100%;
        background: white;
        display: flex;
        justify-content: space-between;

        .top-content-left {
            display: flex;
            justify-content: center;
            align-items: center;

            .router-link-active {
                text-decoration: none;
            }

            img {
                height: 50px;
                width: 50px;
                margin-right: 10px;
            }

            p {
                font-size: 23px;
                color: #e38b00;
            }
        }

        .top-content-right {
            display: flex;
            justify-content: center;
            align-items: center;
            color: #a7abb7;
            font-size: 15px;
            cursor:pointer;
            .top-content-right-help {
                margin-right: 10px;
            }
        }
    }
}
</style>